package com.sysd.mail;

import com.sysd.mail.pop.PopServer;
import com.sysd.mail.smtp.SmtpServer;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import com.sysd.mail.send.SmtpClient;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;


import java.util.concurrent.*;
@SpringBootApplication(exclude={DataSourceAutoConfiguration.class})
public class MailApplication {

    public static void main(String[] args) {
        SpringApplication.run(MailApplication.class, args);
        try {
            /*
             * corePoolSize线程池的核心线程数
             * maximumPoolSize能容纳的最大线程数
             * keepAliveTime空闲线程存活时间
             * unit 存活的时间单位
             * workQueue 存放提交但未执行任务的队列
             * threadFactory 创建线程的工厂类
             * handler 等待队列满后的拒绝策略
             */
            ExecutorService threadPool = new ThreadPoolExecutor(3, 5,
                    10L, TimeUnit.SECONDS,
                    new LinkedBlockingQueue<>(3),
                    Executors.defaultThreadFactory(),
                    new ThreadPoolExecutor.AbortPolicy());
            threadPool.execute(PopServer::popStart);
            threadPool.execute(SmtpServer::smtpStart);
            System.out.println("服务器已经启动!");
        } catch (Exception e) {
            System.out.println("服务器启动异常!");
        }
    }

}
